home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Games / JST / sources / OSEmu / intuition.s < prev    next >
Encoding:
Text File  |  2001-03-19  |  22.5 KB  |  1,175 lines

  1. * $Id: intuition.s 1.1 1999/02/03 04:10:30 jotd Exp jotd $
  2. **************************************************************************
  3. *   INTUITION-LIBRARY                                                    *
  4. **************************************************************************
  5. **************************************************************************
  6. *   INITIALIZATION                                                       *
  7. **************************************************************************
  8.  
  9. POINTER_HEIGHT = 12
  10. NB_MSG_BUFFERS = 10
  11.  
  12. INTUIINIT    move.l    _intbase,d0
  13.         beq    .init
  14.         rts
  15.  
  16. .init        
  17.         ;move.l    #-_LVOBltBitMapRastPort,d0    ; gfx bad copy/paste??
  18.         move.l    #-_LVONextObject,d0
  19.         move.l    #242,d1
  20.         lea    _intname,a0
  21.         bsr    _InitLibrary
  22.         move.l    d0,a0
  23.         move.l    d0,_intbase
  24.         
  25.         patch    _LVOCloseWorkBench(a0),CLOSEWB
  26.         patch    _LVOClearDMRequest(A0),MYRTZ
  27.         patch    _LVOOpenWindow(A0),_OPENWINDOW
  28.         patch    _LVOCloseWindow(A0),_CLOSEWINDOW
  29.         patch    _LVOCloseScreen(A0),_CLOSESCREEN    ; -- added by JOTD
  30.         patch    _LVOShowTitle(A0),MYRTS        ; -- dummy, JOTD
  31.         patch    _LVOClearPointer(A0),_ClearPointer ; JOTD, monkey island
  32.         patch    _LVOClearMenuStrip(A0),MYRTS    ; -- added by JOTD
  33.         patch    _LVOOpenWorkBench(A0),_OPENWB    ; -- added by JOTD
  34.         patch    _LVOAlohaWorkbench(A0),MYRTS    ; -- added by JOTD
  35.         patch    _LVORethinkDisplay(A0),_RethinkDisplay    ; -- added by JOTD
  36.         patch    _LVORemakeDisplay(A0),MYRTS        ; -- added by JOTD
  37.         patch    _LVOCurrentTime(A0),_CURRENTTIME    ; -- added by JOTD (Theatre of death)
  38.         patch    _LVOOpenScreen(A0),_OpenScreen    ; -- added by JOTD (Gobliins 2)
  39.         patch    _LVOOpenScreenTagList(A0),_OpenScreenTagList
  40.         patch    _LVOGetPrefs(A0),_GETPREFS        ; -- added by JOTD
  41.         patch    _LVOSetPrefs(A0),_SETPREFS        ; -- dummy, JOTD
  42.         patch    _LVOSetPointer(A0),_SetPointer    ; -- JOTD, Monkey Island
  43.         patch    _LVOLockIBase(A0),_LOCKIBASE
  44.         patch    _LVOMoveScreen(A0),MYRTS    ; JOTD, Dummy, Loom
  45.         patch    _LVOUnlockIBase(A0),MYRTS    ; JOTD, Darkseed
  46.         patch    _LVOAllocRemember(A0),_ALLOCREMEMBER ; -- slamtilt
  47.         patch    _LVOFreeRemember(A0),_FREEREMEMBER    ; -- slamtilt
  48.         patch    _LVOMakeScreen(A0),_MAKESCREEN
  49.         patch    _LVOScreenToFront(A0),_ScreenToFront ; -- pinball illusions, maniac
  50.         patch    _LVOViewAddress(A0),_ViewAddress
  51.         patch    _LVOViewPortAddress(A0),_ViewPortAddress ; -- lost vikings
  52.         patch    _LVOPubScreenStatus(A0),MYRTS ; -- highseas
  53. ;        patch    _LVOQueryOverscan(A0),_QUERYOVERSCAN ; -- subwar, may be unsuccessful!
  54. ;        patch    _LVOOpenWindowTagList(A0),_OPENWINDOWTAGLIST ; -- subwar, may be unsuccessful!
  55. ;        patch    _LVODisposeObject(A0),MYRTS ; -- subwar
  56.         patch    _LVOReportMouse(A0),_ReportMouse ; -- neuromancer
  57.         patch    _LVOModifyIDCMP(A0),_ModifyIDCMP ; -- neuromancer
  58. ;        patch    _LVOMoveScreen(A0),MYRTS ; -- loom
  59.         patch    _LVOWBenchToFront(A0),_WBenchToFront
  60.         patch    _LVOWBenchToBack(A0),_WBenchToBack
  61.  
  62.         movem.l    D0-A6,-(A7)
  63.  
  64.         ; init ViewLord structure
  65.  
  66.         move.l    _intbase,A0
  67.         lea    ib_ViewLord(A0),A1
  68.         bsr    _InitView    ; from graphics lib
  69.  
  70.         ; init active window/screen pointers
  71.  
  72.         move.l    _intbase,A0
  73.         clr.l    ib_ActiveWindow(A0)
  74.         clr.l    ib_ActiveScreen(A0)
  75.  
  76.         ; opens a default screen
  77.  
  78.         move.l    A0,A6        ; library base
  79.  
  80.         lea    newscreen_struct(pc),A0
  81.         bsr    _OpenScreen
  82.         move.l    ib_ActiveScreen(A6),A1
  83.         lea    newwindow_struct(pc),A0
  84.         move.l    A1,nw_Screen(A0)
  85.         bsr    _OPENWINDOW
  86.  
  87.         ; opens input.device to process mouse/kbd events
  88.  
  89.         bsr    add_input_handler
  90.  
  91.         movem.l    (A7)+,D0-A6
  92.         rts
  93.  
  94. .fail        EMUFAIL    _LVOOpenLibrary,_intname
  95.  
  96. ; rem_input_handler, dirty intuition input handler removal
  97. ; also removes mouse pointer sprite
  98. ; < A0: intuition interrupt structure
  99.     
  100. rem_input_handler:
  101.     movem.l    D0-A6,-(A7)
  102.     move.l    A0,A1
  103.     move.l    #$16,D0
  104.     move.l    $4.W,A6
  105.     JSRLIB    FreeMem
  106.  
  107. ;    move.l    _intbase(pc),A6
  108. ;    move.l    (ib_ActiveWindow,A6),A0
  109. ;    JSRLIB    ClearPointer
  110.  
  111.     move.l    _gfxbase(pc),A6
  112.     moveq.l    #0,D0
  113.     JSRLIB    FreeSprite
  114.  
  115.     movem.l    (A7)+,D0-A6
  116.     rts
  117.  
  118. add_input_handler:
  119.         tst.l    _inputhandler    ; trick don't insert handler
  120.         bne    .exit        ; if already one there
  121.  
  122.         ; first; open input.device
  123.  
  124.         lea    _inpname(pc),A0
  125.         moveq.l    #0,D0
  126.         moveq.l    #0,D1
  127.         lea    -64(A7),A7
  128.         move.l    A7,A1
  129.         move.l    $4.W,A6
  130.         JSRLIB    OpenDevice
  131.  
  132.         move.l    #$16,D0
  133.         move.l    #MEMF_CLEAR|MEMF_PUBLIC|MEMF_CLEAR,D1
  134.         JSRLIB    AllocMem
  135.         move.l    D0,A5        ; A5: input handler structure        
  136.  
  137.         lea    IntuitionInputHandler(pc),A0
  138.         move.l    A0,(IS_CODE,A5)
  139.         move.l    _intbase,(IS_DATA,A5)
  140.                 
  141.         move.l    A7,A1
  142.         move.l    A5,(IO_DATA,A1)
  143.  
  144.         move.l    (A5),A5        ; node
  145.         move.l    #.handlername,(LN_NAME,A5)
  146.         move.b    #100,(LN_PRI,A5)
  147.  
  148.         move.w    #IND_ADDHANDLER,(IO_COMMAND,A1)
  149.         JSRLIB    DoIO
  150.  
  151.         lea    64(A7),A7
  152. .exit
  153.         rts
  154. .handlername:
  155.     dc.b    "Intuition OSEmu Input Handler",0
  156.     even
  157.  
  158.     
  159. newscreen_struct:
  160.     dc.w    0,0
  161.     dc.w    320,200
  162.     dc.w    2
  163.     dc.w    1,0
  164.     dc.W    0
  165.     dc.W    0
  166.     dc.l    0    ; font
  167.     dc.l    .title
  168.     dc.l    0
  169.     dc.l    0
  170.  
  171. .title:
  172.     dc.b    "title",0
  173.     even
  174.  
  175. newwindow_struct:
  176.     dc.w    0,0
  177.     dc.w    320,200
  178.     dc.w    0
  179.     dc.l    0,0,0,0
  180.     dc.l    .title
  181.     dc.l    0,0
  182.     dc.w    10,10,320,200
  183.     dc.w    0
  184.  
  185. .title:
  186.     dc.b    "title",0
  187.     even
  188.  
  189. _CursorSpriteData:
  190.     dc.l    0
  191.  
  192. _CursorSpriteStruct:
  193.     dc.l    0
  194.     dc.w    POINTER_HEIGHT
  195.     dc.w    0,0    ; X,Y
  196.     dc.w    0    ; sprite number
  197.  
  198. ; input handler
  199.  
  200. IntuitionInputHandler:
  201.     movem.l    D0-D7/A0-A6,-(A7)
  202.  
  203.     move.l    A1,A4        ; IntuitionBase
  204.     
  205.     ; check if key pressed
  206.  
  207.     cmp.b    #IECLASS_RAWKEY,(ie_Class,a0)
  208.     bne.b    .norawkey
  209.  
  210.     move.l    A0,A5        ; event
  211.  
  212.     bsr    _init_event
  213.     tst.l    D0
  214.     bne    .exit        ; ignore it
  215.  
  216.     ; event is processed
  217.  
  218.     move.l    #IDCMP_RAWKEY,(im_Class,A3)
  219.     move.w    (ie_Code,A5),(im_Code,A3)
  220.     move.w    (ie_Qualifier,A5),(im_Qualifier,A3)
  221.  
  222.     ; puts the message in the window message port
  223.  
  224.     move.l    $4.W,A6
  225.     move.l    (ib_ActiveWindow,A4),A0
  226.     move.l    (wd_UserPort,A0),A0
  227.     move.l    A3,A1
  228.     JSRLIB    PutMsg
  229.  
  230.     bra    .exit
  231.  
  232. .norawkey
  233.     
  234.     cmp.b    #IECLASS_RAWMOUSE,(ie_Class,a0)
  235.     bne    .exit
  236.     cmp.w    #IECODE_NOBUTTON,(ie_Code,a0)
  237.     bne    .checkbuttons
  238.  
  239.     ; mouse pointer just moved
  240.  
  241.     move.l    (ib_ActiveWindow,A4),A2
  242.  
  243.     move.w    (ie_X,a0),D0
  244.     move.w    (wd_MouseX,a2),D2
  245.  
  246.     add.w    D2,D0
  247.     bmi    .leftend
  248.     cmp.w    (wd_Width,a2),D0
  249.     bcc    .rightend
  250. .endx
  251.     move.w    (ie_Y,a0),D1
  252.     move.w    (wd_MouseY,a2),D2
  253.  
  254.     add.w    D2,D1
  255.     bmi    .upend
  256.     cmp.w    (wd_Height,a2),D1
  257.     bcc    .downend
  258. .endy
  259.     ; update window structure
  260.  
  261.     move.w    D0,(wd_MouseX,a2)
  262.     move.w    D1,(wd_MouseY,a2)
  263.  
  264.     ; moves the sprite
  265.  
  266.     movem.l    D0-D1,-(A7)
  267.     sub.l    A0,A0    ; no view port!
  268.     lea    _CursorSpriteStruct(pc),A1
  269.     move.l    _gfxbase(pc),A6
  270.     JSRLIB    MoveSprite
  271.     movem.l    (A7)+,D0-D1
  272.  
  273.     ; update screen structure
  274.  
  275.     move.l    (ib_ActiveScreen,A4),A0
  276.     move.b    (wd_XOffset,A2),D3
  277.     ext.w    D3
  278.     sub.w    D3,D0
  279.     move.w    D0,(sc_MouseX,A0)
  280.     move.b    (wd_YOffset,A2),D3
  281.     ext.w    D3
  282.     sub.w    D3,D1
  283.     move.w    D1,(sc_MouseY,A0)
  284.  
  285.     bra    .exit
  286. .checkbuttons
  287.     move.l    A0,A5        ; event
  288.  
  289.     bsr    _init_event
  290.     tst.l    D0
  291.     bne    .exit        ; ignore it
  292.  
  293.     ; event is processed
  294.  
  295.     move.l    #IDCMP_MOUSEBUTTONS,(im_Class,A3)
  296.     move.w    (ie_Code,A5),(im_Code,A3)
  297.     clr.w    (im_Qualifier,A3)
  298.  
  299.     ; puts the message in the window message port
  300.  
  301.     move.l    $4.W,A6
  302.     move.l    (ib_ActiveWindow,A4),A0
  303.  
  304.     move.l    (wd_UserPort,A0),A0
  305.     move.l    A3,A1
  306.     JSRLIB    PutMsg
  307.     
  308. .exit:
  309.     movem.l    (A7)+,D0-D7/A0-A6
  310.     rts
  311.  
  312. .upend:
  313.     clr.w    D1
  314.     bra    .endy
  315. .downend:
  316.     move.w    (wd_Height,a2),D1
  317.     bra    .endy
  318. .leftend:
  319.     clr.w    D0
  320.     bra    .endx
  321. .rightend:
  322.     move.w    (wd_Width,a2),D0
  323.     bra    .endx
  324.  
  325. ; _init_event, internal function
  326. ; < A4: intuition base
  327. ; < A5: event
  328. ; > A3: IDCMP message
  329. ; all registers except A4 and A5 are destroyed
  330.  
  331. _init_event:
  332.  
  333.     lea    .messages,A3
  334.     moveq.l    #NB_MSG_BUFFERS-1,D0
  335.     move.l    #$34,D2        ; sizeof(IntuiMessage)
  336.     
  337. .loop:
  338.     cmp.b    #NT_MESSAGE,(LN_TYPE,A3)
  339.     bne.b    .avail
  340.     add.l    D2,A3
  341.     dbf    D0,.loop
  342.     bra.b    .notreplied    ; event buffer overflow, discard
  343.  
  344. .avail:
  345.     move.l    D2,(MN_LENGTH,A3)
  346.     move.b    #NT_MESSAGE,(LN_TYPE,A3)
  347.  
  348.     move.l    (ib_ActiveWindow,A4),A0
  349. ;;    move.l    (wd_UserPort,A0),(MN_REPLYPORT,A3)
  350.     clr.l    (MN_REPLYPORT,A3)    ; no reply port
  351.  
  352.     move.l    A0,(im_IDCMPWindow,A3)
  353.     move.l    #.deadkey_info,(im_IAddress,A3)
  354.  
  355.     ; composes event mouse X & mouse Y
  356.  
  357.     move.w    (wd_MouseX,A0),(im_MouseX,A3)
  358.     move.w    (wd_MouseY,A0),(im_MouseY,A3)
  359.  
  360.     ; timestamp the event
  361.  
  362.     lea    (im_Seconds,A3),A0
  363.     lea    (im_Micros,A3),A1
  364.     move.l    A4,A6            ; intuition
  365.     JSRLIB    CurrentTime
  366.  
  367.     moveq.l    #0,d0
  368.     rts
  369.  
  370. .notreplied:
  371.     moveq.l    #-1,D0
  372.     RTS
  373.  
  374. .deadkey_info:
  375.     dc.l    0
  376.  
  377. ; buffers for input events
  378.  
  379. .messages:
  380.     blk.b    $34*NB_MSG_BUFFERS,0
  381.  
  382. **************************************************************************
  383. *   SCREEN FUNCTIONS                                                     *
  384. **************************************************************************
  385.  
  386. _ScreenToFront:
  387.     move.l    A0,ib_ActiveScreen(A6)    ; now this is the active screen
  388.     RTS
  389.  
  390.  
  391. _MAKESCREEN:
  392.     lea    sc_ViewPort(a0),a1
  393.     lea    ib_ViewLord(a6),a0
  394.     bsr    _MakeVPort        ; from graphics.library
  395.     rts
  396.  
  397. ; OpenScreenTagList()
  398. ; Written by JOTD
  399. ; < A0: NewScreen structure
  400. ; < A1: Tags
  401. ; > D0: Screen structure
  402.  
  403.  
  404. _OpenScreenTagList:
  405.     movem.l    D1-A6,-(A7)
  406.     cmp.l    #0,A0
  407.     bne.b    .userstruct
  408.     lea    newscreen_struct(pc),A0
  409. .userstruct:
  410. .loop
  411.     move.l    (A1)+,D1    ; tag
  412.     beq.b    .end
  413.  
  414.     move.l    (A1)+,D2    ; data
  415.  
  416.     cmp.l    #SA_Left,D1
  417.     bne.b    .noleft
  418.     move.w    D2,ns_LeftEdge(A0)
  419.     bra.b    .loop
  420. .noleft:
  421.     cmp.l    #SA_Top,D1
  422.     bne.b    .notop
  423.     move.w    D2,ns_TopEdge(A0)
  424.     bra.b    .loop
  425. .notop
  426.     cmp.l    #SA_Width,D1
  427.     bne.b    .nowidth
  428.     move.w    D2,ns_Width(A0)
  429.     bra.b    .loop
  430. .nowidth
  431.     cmp.l    #SA_Height,D1
  432.     bne.b    .noheight
  433.     move.w    D2,ns_Height(A0)
  434.     bra.b    .loop
  435. .noheight:
  436.     ; don't care about other tags ATM
  437.     bra.b    .loop
  438. .end:
  439.     bsr    _OpenScreen
  440.     movem.l    (A7)+,D1-A6
  441.     tst.l    D0
  442.     rts
  443.     
  444. ; OpenScreen()
  445. ; Written by JOTD
  446. ; < A0: NewScreen structure
  447. ; > D0: Screen structure
  448.  
  449. _OpenScreen:
  450.     movem.l    D1-A6,-(A7)
  451.  
  452.     move.l    A0,A5            ; newscreen struct
  453.  
  454.     move.l    #$15A,D0        ; sizeof(Screen)
  455.     move.l    #MEMF_CLEAR,D1
  456.     bsr    ForeignAllocMem
  457.     move.l    D0,A0            ; screen structure
  458.  
  459.     move.l    #($15A/4)-1,D0        ; sizeof(Screen)
  460.     move.l    A0,A1
  461. .tm
  462.     move.l    #$EEEEEEEE,(A1)+
  463.     DBF    D0,.tm
  464.  
  465.     move.l    ib_ActiveScreen(A6),sc_NextScreen(A0)    ; other screen saved
  466.     clr.l    sc_FirstWindow(A0)    ; no windows ATM
  467.     move.w    ns_LeftEdge(A5),sc_LeftEdge(A0)
  468.     move.w    ns_TopEdge(A5),sc_TopEdge(A0)
  469.     move.w    ns_Width(A5),sc_Width(A0)
  470.     move.w    ns_Height(A5),sc_Height(A0)
  471.     move.w    ns_Type(A5),sc_Flags(A0)
  472.     clr.w    sc_MouseX(A0)
  473.     clr.w    sc_MouseY(A0)
  474.     move.l    #_TOPAZ8FONT,sc_Font(A0)
  475.  
  476.     move.b    ns_DetailPen(A5),sc_DetailPen(A0)
  477.     move.b    ns_BlockPen(A5),sc_BlockPen(A0)
  478.  
  479.     move.l    ns_DefaultTitle(A5),sc_DefaultTitle(A0)
  480.  
  481.     ; initializes ViewPort structure
  482.  
  483.     move.l    A0,A4        ; screen structure
  484.     lea    sc_ViewPort(A4),A0
  485.     bsr    _InitVPort
  486.     lea    sc_ViewPort(A4),A0
  487.     move.l    #_INITRASINFO,vp_RasInfo(A0)    ; share with graphics.library rasinfo
  488.     
  489.     ; initializes RastPort structure
  490.  
  491.     lea    sc_RastPort(A4),A1
  492.     bsr    _InitRastPort
  493.  
  494.     ; initializes bitmap
  495.  
  496.     lea    sc_BitMap(A4),A0
  497.     move.w    ns_Depth(A5),D0
  498.     move.w    ns_Width(A5),D1
  499.     move.w    ns_Height(A5),D2
  500.     bsr    _InitBitMap
  501.  
  502.     ; allocates bitplanes
  503.  
  504.     lea    sc_BitMap(A4),A0
  505.     bsr    _internal_AllocBitPlanes
  506.  
  507.     ; copies bitmap to rastport.bitmap
  508.     
  509.     lea    sc_BitMap(A4),A0
  510.     lea    sc_RastPort(A4),A1
  511.     lea    rp_BitMap(A1),A1
  512.     move.l    #9,D0
  513. .copy
  514.     move.l    (A0)+,(A1)+
  515.     dbf    D0,.copy
  516.  
  517.     lea    sc_BitMap(A4),A0
  518.     move.l    sc_ViewPort+vp_RasInfo(A4),A3    ; pointer on rasinfo struct
  519.     move.l    A0,(ri_BitMap,A3)    ; puts the bitmap into rasinfo struct
  520.  
  521.     ; makes the view
  522.  
  523. ;    lea    (ib_ViewLord,A6),A0    ; view
  524. ;    lea    (sc_ViewPort,A4),A1
  525. ;    bsr    _MakeVPort        
  526.  
  527.     ifeq    1
  528.     ; gets colormap
  529.  
  530.     moveq.l    #1,D0
  531.     move.w    ns_Depth(A5),D1
  532.     lsl.w    D1,D0        ; computes number of colors
  533.  
  534.     bsr    _GETCOLORMAP
  535.     lea    sc_ViewPort(A4),A0
  536.     move.l    D0,vp_ColorMap(A0)
  537.     endif
  538.  
  539.  
  540.     move.l    A4,ib_ActiveScreen(A6)    ; sets active screen
  541.     move.l    a4,ib_FirstScreen(A6)    ; sets first screen (Harry)
  542.  
  543.     move.l    A4,D0            ; return value
  544.  
  545.     movem.l    (A7)+,D1-A6
  546.  
  547.     rts
  548.  
  549. _OPENWB:
  550.     moveq.l    #1,D0    ; non-NULL
  551.     rts
  552.  
  553. ISCLOSED
  554.     dc.l    0    ; added by JOTD
  555.  
  556. ;since there is no workbench, closing should awlays return 0 for success
  557. ;but some programs loop until the routine returns false (ok the wb is closed)
  558.  
  559. CLOSEWB
  560.     movem.l    A0,-(A7)
  561.     lea    ISCLOSED(pc),A0
  562.     move.l    (A0),D0        ; first time returns 0, and 1 afterwards
  563.     move.l    #1,(A0)
  564.     movem.l    (A7)+,A0
  565.     RTS
  566.  
  567. ; < A0: PrefBuffer
  568. ; < D0: Size
  569. ; < D1: notify
  570. ; > D0: returns PrefBuffer
  571.  
  572. _SETPREFS:
  573.     lea    prefsdata(pc),A1
  574.  
  575.     move.l    D0,D1
  576.     subq.l    #1,D1
  577.  
  578.     move.l    A0,D0    ; prepare return value
  579.  
  580. .copy
  581.     move.b    (A0)+,(A1)+
  582.     dbf    D1,.copy
  583.     rts
  584.  
  585. ; < A0: PrefBuffer
  586. ; < D0: Size
  587. ; > D0: returns PrefBuffer
  588.  
  589. _GETPREFS
  590.     bsr    .read_prefs
  591.  
  592.     lea    prefsdata(pc),A1
  593.  
  594.     move.l    D0,D1
  595.     subq.l    #1,D1
  596. .copy
  597.     move.b    (A1)+,(A0)+
  598.     dbf    D1,.copy
  599.     rts
  600.  
  601. .read_prefs:
  602.     movem.l    D0-A6,-(A7)
  603.     move.l    _dosbase(pc),A6
  604.     move.l    #MODE_OLDFILE,D2
  605.     move.l    #.sysconf_name,D1
  606.     JSRLIB    Open
  607.     move.l    D0,D6
  608.     bne.b    .ok
  609.  
  610.     ; not found in devs, try in root directory
  611.  
  612.     move.l    #MODE_OLDFILE,D2
  613.     move.l    #.sysconf_name2,D1
  614.     JSRLIB    Open
  615.     move.l    D0,D6
  616.     beq.b    .out
  617.  
  618. .ok
  619.     move.l    D6,D1
  620.     move.l    #prefsdata,D2
  621.     move.l    #232,D3
  622.     JSRLIB    Read
  623.  
  624.     move.l    D6,D1
  625.     JSRLIB    Close
  626. .out
  627.     movem.l    (A7)+,D0-A6
  628.     rts
  629.  
  630. .sysconf_name:
  631.     dc.b    ":devs/system-configuration",0
  632.     even
  633.  
  634. .sysconf_name2:
  635.     dc.b    ":system-configuration",0
  636.     even
  637.  
  638. _OPENWINDOW
  639.         MOVE.L    A0,-(A7)
  640.         MOVE.L    #$88,D0
  641.         MOVE.L    #MEMF_CLEAR,D1
  642.         bsr    ForeignAllocMem
  643.         MOVE.L    D0,A1
  644.  
  645.         move.l    #($88/4)-1,D0        ; sizeof(Window)
  646.         move.l    A1,A0
  647. .tm
  648.         move.l    #$EEEEEEEE,(A0)+
  649.         DBF    D0,.tm
  650.  
  651.         ; allocates memory for message & rastport
  652.         ; (as OSEmu is rather greedy in memory, let's group both structures)
  653.  
  654.         movem.l    A1/A6,-(A7)
  655.         MOVE.L    #$64,D0
  656.         MOVE.L    #MEMF_CLEAR,D1
  657.         move.l    $4.W,A6
  658.         JSRLIB    AllocMem
  659.         movem.l    (A7)+,A1/A6
  660.  
  661.         MOVE.L    D0,wd_RPort(A1)            ; stores rastport
  662.         move.l    A1,-(A7)
  663.         move.l    D0,A1
  664.         bsr    _InitRastPort
  665.         
  666.         move.l    A6,-(A7)
  667.         move.l    $4.W,A6
  668.         JSRLIB    CreateMsgPort        ; initializes window message port
  669.         move.l    (A7)+,A6
  670.  
  671.         move.l    (A7),A1
  672.  
  673.         move.l    D0,wd_UserPort(A1)    ; user port to add to ports list
  674.  
  675.         ; call AddPort
  676.  
  677.         MOVE.L    wd_UserPort(A1),A1
  678.  
  679.         move.l    A6,-(A7)
  680.         move.l    $4.W,A6
  681.         JSRLIB    AddPort        
  682.         move.l    (A7)+,A6
  683.  
  684.         MOVE.L    (A7)+,A1
  685.  
  686.         MOVE.L    (A7)+,A0
  687.  
  688.         MOVE.L    nw_LeftEdge(A0),wd_LeftEdge(A1)
  689.         MOVE.L    nw_TopEdge(A0),wd_TopEdge(A1)
  690.         MOVE.L    nw_Width(A0),wd_Width(A1)
  691.         MOVE.L    nw_Screen(A0),wd_WScreen(A1)
  692.         MOVE.W    nw_DetailPen(A0),wd_DetailPen(A1)
  693.         MOVE.L    nw_IDCMPFlags(A0),wd_IDCMPFlags(A1)
  694.         MOVE.L    nw_Flags(A0),wd_Flags(A1)
  695.         MOVE.L    nw_FirstGadget(A0),wd_FirstGadget(A1)
  696.         MOVE.L    nw_CheckMark(A0),wd_CheckMark(A1)
  697.         MOVE.L    nw_Title(A0),wd_Title(A1)
  698.         MOVE.L    nw_Screen(A0),wd_WScreen(A1)
  699.         MOVE.L    nw_MinWidth(A0),wd_MinWidth(A1)
  700.         MOVE.L    nw_MaxWidth(A0),wd_MaxWidth(A1)
  701.         MOVE.L    nw_MinHeight(A0),wd_MinHeight(A1)
  702.         MOVE.L    nw_MaxHeight(A0),wd_MaxHeight(A1)
  703.  
  704.         clr.b    wd_BorderLeft(A1)
  705.         clr.b    wd_BorderTop(A1)
  706.         clr.b    wd_BorderRight(A1)
  707.         clr.b    wd_BorderBottom(A1)
  708.  
  709.         move.l    A1,ib_ActiveWindow(A6)    ; sets intuition active window
  710.  
  711.         move.l    A1,D0        ; return value
  712.  
  713.         move.l    wd_WScreen(A1),A1     ; parent screen
  714.         move.l    D0,sc_FirstWindow(A1)    ; this window is the first window
  715.  
  716.         move.l    D0,A1
  717.         ; creates/allocates sprite pointer
  718.  
  719.         ; pointer starts at 0
  720.  
  721.         move.w    #0,(wd_MouseY,A1)
  722.         move.w    #0,(wd_MouseX,A1)
  723.  
  724.         RTS
  725.  
  726. ; < A1: window pointer
  727. create_sprite_pointer:
  728.     tst.l    _CursorSpriteData
  729.     bne    .end
  730.  
  731.     movem.l    D0-A6,-(A7)
  732.  
  733.     move.l    A0,A3        ; window pointer there
  734.  
  735.     move.l    #4+(POINTER_HEIGHT*2*2)+4,D0
  736.     move.l    #MEMF_CHIP|MEMF_CLEAR,D1
  737.     move.l    $4.W,A6
  738.     JSRLIB    AllocMem
  739.     move.l    D0,_CursorSpriteData
  740.     beq    .fail        ; could not allocate memory
  741.  
  742.     move.l    D0,A2
  743.  
  744.     ; gets next sprite
  745.  
  746.     lea    _CursorSpriteStruct(pc),A1
  747.     moveq.l    #-1,D0    ; any
  748.     move.l    _gfxbase(pc),A6
  749.     JSRLIB    GetSprite
  750.     tst.l    D0
  751.     bmi    .fail        ; could not allocate a sprite    
  752.  
  753.     lea    .sprite_data(pc),A0
  754.     move.l    A2,A1
  755.     moveq.l    #POINTER_HEIGHT*2-1,D0
  756. .pcopy
  757.     move.l    (A0)+,(A1)+
  758.     dbf    D0,.pcopy
  759.  
  760.     lea    _CursorSpriteStruct(pc),A1
  761.     sub.l    A0,A0    ; no view port!
  762.     move.w    #POINTER_HEIGHT,(ss_height,A1)
  763.     JSRLIB    ChangeSprite
  764.  
  765.     ; sets definitions in window structure
  766.  
  767.     move.l    A2,(wd_Pointer,A3)
  768.     move.w    #POINTER_HEIGHT,(wd_PtrHeight,A3)
  769.     move.w    #$10,(wd_PtrWidth,A3)
  770.     clr.b    (wd_XOffset,A3)
  771.     clr.b    (wd_YOffset,A3)
  772.  
  773.     ; moves sprite according to window struct
  774.  
  775.     lea    _CursorSpriteStruct(pc),A1
  776.     sub.l    A0,A0
  777.     move.w    (wd_MouseX,A3),D0
  778.     move.w    (wd_MouseY,A3),D1
  779.     JSRLIB    MoveSprite
  780.  
  781.     movem.l    (A7)+,D0-A6
  782. .end
  783.     rts
  784.         
  785. .fail        EMUFAIL    _LVOOpenWindow,_intname
  786. .sprite_data:
  787.     dc.w    $1C0,$80
  788.     dc.w    $1C0,$80
  789.     dc.w    $1C0,$80
  790.     dc.w    $3E0,$1C0
  791.     dc.w    $5D0,$80
  792.     dc.w    $3E3E,$410
  793.     dc.w    $3E3E,$3E3E
  794.     dc.w    $3E3E,$410
  795.     dc.w    $5D0,$80
  796.     dc.w    $3E0,$1C0
  797.     dc.w    $1C0,$80
  798.     dc.w    $1C0,$80
  799.  
  800.     dc.w    $1C0,$80
  801.     dc.w    $1C0,$80
  802.     dc.w    $1C0,$80
  803.     dc.w    $3E0,$1C0
  804.     dc.w    $5D0,$80
  805.     dc.w    $FFFF,$410
  806.     dc.w    $FFFF,$FFFF
  807.     dc.w    $FFFF,$410
  808.     dc.w    $5D0,$80
  809.     dc.w    $3E0,$1C0
  810.     dc.w    $1C0,$80
  811.     dc.w    $1C0,$80
  812.  
  813.  
  814. ; close screen, untested
  815. ; < A0: screen
  816. _CLOSESCREEN
  817.     move.l    A0,A1
  818.     lea    sc_BitMap(A1),A0
  819.  
  820.     ; frees bitplanes
  821.  
  822.     bsr    _internal_FreeBitPlanes
  823.  
  824.     ; frees screen structure
  825.  
  826.     move.l    #$15A,D0        ; sizeof(Screen)
  827.     bsr    ForeignFreeMem
  828.     rts
  829.  
  830.  
  831. ; < A0: window
  832. _CLOSEWINDOW
  833.         MOVE.L    A0,A1
  834.         MOVE.L    #$88,D0
  835.  
  836.         move.l    wd_WScreen(A1),A0     ; parent screen
  837.         clr.l    sc_FirstWindow(A0)    ; no more windows on screen
  838.  
  839.         movem.l    A6,-(A7)
  840.         move.l    $4.W,A6
  841.  
  842.         ; removes port from ports list
  843.  
  844.         movem.l    D0/A1,-(A7)
  845.         move.l    wd_UserPort(A1),A1    ; user port to remove from ports list
  846.         JSRLIB    RemPort        
  847.         movem.l    (A7)+,D0/A1
  848.  
  849.         ; frees rastport memory
  850.  
  851.         movem.l    D0/A1,-(A7)
  852.         MOVE.L    #$64,D0
  853.         move.l    wd_RPort(A1),A1
  854.         JSRLIB    FreeMem
  855.         movem.l    (A7)+,D0/A1
  856.  
  857.         ; deletes message port
  858.  
  859.         movem.l    D0/A1,-(A7)
  860.         move.l    wd_RPort(A1),A0
  861.         JSRLIB    DeleteMsgPort
  862.         movem.l    (A7)+,D0/A1
  863.  
  864.         ; frees window structure
  865.  
  866.         JSRLIB    FreeMem
  867.         movem.l    (A7)+,A6
  868.  
  869.         RTS
  870.  
  871. _LOCKIBASE    MOVE.L    #'MYLK',D0
  872.         RTS
  873.         
  874. **************************************************************************
  875. *   ICON-LIBRARY                                                         *
  876. **************************************************************************
  877. **************************************************************************
  878. *   INITIALIZATION                                                       *
  879. **************************************************************************
  880.  
  881. ILIBINIT    move.l    _ilibbase,d0
  882.         beq    .init
  883.         rts
  884.  
  885. .init        move.l    #-_LVOBumpRevision,d0
  886.         move.l    #LIB_SIZE,D1
  887.         lea    _ilibname,a0
  888.         bsr    _InitLibrary
  889.         move.l    d0,a0
  890.         move.l    d0,_ilibbase
  891.         
  892.         patch    _LVOGetDiskObject(a0),MYRTZ
  893.  
  894.         rts
  895.  
  896.  
  897. **************************************************************************
  898. *   LAYERS-LIBRARY                                                       *
  899. **************************************************************************
  900. **************************************************************************
  901. *   INITIALIZATION                                                       *
  902. **************************************************************************
  903.  
  904. LAYERSINIT    move.l    _laybase,d0
  905.         beq    .init
  906.         rts
  907.  
  908. .init        move.l    #-_LVOMoveLayerInFrontOf,d0
  909.         move.l    #LIB_SIZE,D1
  910.         lea    _layname,a0
  911.         bsr    _InitLibrary
  912.         move.l    d0,a0
  913.         move.l    d0,_laybase
  914.         
  915.         rts
  916.  
  917. ; mathffp, mathtrans stuff relocated in specific files
  918.  
  919. _CURRENTTIME:                ; added by JOTD
  920.     move.l    sec_timer,(A0)
  921.     move.l    microsec_timer,(A1)
  922.     rts
  923.  
  924. ; AllocRemember (needed by SlamTilt)
  925. ;
  926. ; <A0: struct Remember to allocate
  927. ; <D0: size
  928. ; <D1: flags
  929. ; >D0: allocated block
  930. ; >(A0): "structure"
  931.  
  932. _ALLOCREMEMBER:
  933.     movem.l    D2/A2,-(A7)
  934.  
  935.     bsr    .find_free_node
  936.  
  937.     add.l    #$10,D0        ; adds $10 bytes to the required size
  938.                 ; (4 is not enough for proper alignment)
  939.     move.l    D0,D2        ; save size
  940.  
  941.     ; perform alloc
  942.  
  943.     move.l    A0,-(A7)
  944.     bsr    ForeignAllocMem
  945.     move.l    (A7)+,A0
  946.  
  947.     move.l    D0,(A0)        ; initialize structure
  948.     beq.b    .fail        ; allocation failed
  949.     move.l    D0,A2
  950.  
  951.     clr.l    (A2)        ; set NEXT to NULL
  952.     move.l    D2,(4,A2)    ; set size as second longword of the allocated buffer
  953.                 ; A0 points on allocated block with size info
  954.     add.l    #$10,D0        ; D0 points on allocated buffer
  955. .end
  956.     movem.l    (A7)+,D2/A2
  957.     rts
  958. .fail
  959.     bra.b    .end
  960.  
  961. ;< A0: struct Remember
  962. ;> A0: free node buffer
  963.  
  964. .find_free_node:
  965. .loop
  966.     tst.l    (A0)        ; next available?
  967.     beq.b    .found        ; yep
  968.     move.l    (A0),A0        ; next please
  969.     bra.b    .loop
  970. .found:
  971.     rts
  972.  
  973. ; <A0: RememberKey
  974. ; <D0:= 0: just free the structure
  975. ;     !=0: free struct & free memory
  976.  
  977. _FREEREMEMBER:
  978.     tst.l    (A0)
  979.     beq.b    .exit
  980.     move.l    (A0),A1
  981.     clr.l    (A0)    ; zero the struct Remember * pointer
  982.  
  983.     tst.l    D0
  984.     beq.b    .exit    ; FALSE: do nothing
  985.  
  986.     move.l    A1,A0    ; restore A0 value
  987. .loop
  988.     cmp.l    #0,A0        ; end of list?
  989.     beq.b    .exit
  990.     move.l    A0,A1        ; buffer
  991.     move.l    (4,A0),D0    ; size
  992.     move.l    (A0),A0        ; next
  993.  
  994.     move.l    A0,-(A7)
  995.     bsr    ForeignFreeMem
  996.     move.l    (A7)+,A0
  997.  
  998.     bra.b    .loop
  999. .exit
  1000.     rts
  1001.  
  1002. ; < A0: window
  1003. ; > D0: view port address of the screen
  1004. ; (matches AROS implementation, and probably original OS too)
  1005.  
  1006. _ViewPortAddress:
  1007.     move.l    wd_WScreen(A0),A0    ; the screen of the window
  1008.     lea    sc_ViewPort(a0),A0    ; viewport address
  1009.     move.l    A0,D0            ; in D0
  1010.     rts
  1011.  
  1012. ; < D0: view
  1013. ; (matches AROS implementation, and probably original OS too)
  1014.  
  1015. _ViewAddress:
  1016.     lea    ib_ViewLord(A6),A0
  1017.     move.l    A0,D0
  1018.     rts
  1019.  
  1020. ; dummy, always returns true
  1021.  
  1022. _QUERYOVERSCAN:
  1023.     moveq    #-1,D0    ; success
  1024.     rts
  1025.  
  1026. ; dummy, returns initialization screen
  1027.  
  1028. _OPENWINDOWTAGLIST:
  1029.     move.l    ib_ActiveWindow(A6),D0
  1030.     rts
  1031.  
  1032. ; added by JOTD
  1033. ; First calls MakeVPort
  1034. ; then MrgCop
  1035. ; then LoadView
  1036.  
  1037. _RethinkDisplay    
  1038.     movem.l    a2/a5/a6,-(A7)
  1039.     move.l    A6,A5        ; save intuition base
  1040.     move.l    (ib_ActiveScreen,A5),A2
  1041.     move.l    _gfxbase,A6        ; I hope gfxbase is active!!
  1042.     lea    (sc_ViewPort,a2),A1    ; ViewPort structure
  1043.     lea    (ib_ViewLord,A5),A0    ; user intuition view structure
  1044.     move.l    A1,(v_ViewPort,A0)    ; set viewport in view
  1045.     JSRLIB    MakeVPort        ; build copperlist
  1046.  
  1047.     lea    (ib_ViewLord,A5),A1
  1048.     JSRLIB    MrgCop            ; merges copperlists
  1049.  
  1050.     lea    (ib_ViewLord,A5),A1
  1051.     JSRLIB    LoadView        ; loads the view
  1052.     
  1053.     movem.l    (A7)+,a2/a5/a6
  1054.     rts
  1055.  
  1056. _internal_AllocBitPlanes:    ; A0: bitmap
  1057.     movem.l    D0-A6,-(A7)
  1058.     move.w    (bm_BytesPerRow,a0),d1
  1059.     move.w    (bm_Rows,a0),d2
  1060.     mulu d1,d2
  1061.     moveq    #0,D3
  1062.     move.b    (bm_Depth,A0),D3
  1063.     lea    (bm_Planes,A0),A2
  1064.     subq.l    #1,D3
  1065.     move.l    $4.W,A6
  1066. .allocloop:
  1067.     move.l    D2,D0                ; size
  1068.     move.l    #MEMF_CHIP|MEMF_CLEAR,D1    ; reqs
  1069.     JSRLIB    AllocMem
  1070.     move.l    D0,(A2)+
  1071.     beq.b    .fail
  1072.     dbf    D3,.allocloop
  1073.  
  1074.     movem.l    (A7)+,D0-A6
  1075.     rts
  1076.  
  1077. .fail
  1078.     EMUFAIL    _LVOInitBitMap,_gfxname
  1079.  
  1080. _internal_FreeBitPlanes:    ; A0: bitmap
  1081.     movem.l    D0-A6,-(A7)
  1082.     move.w    (bm_BytesPerRow,a0),d1
  1083.     move.w    (bm_Rows,a0),d2
  1084.     mulu d1,d2
  1085.     moveq    #0,D3
  1086.     move.b    (bm_Depth,A0),D3
  1087.     lea    (bm_Planes,A0),A2
  1088.     subq.l    #1,D3
  1089.     move.l    $4.W,A6
  1090. .allocloop:
  1091.     move.l    (A2),A1    ; address
  1092.     move.l    D2,D0        ; size
  1093.     JSRLIB    FreeMem
  1094.     move.l    #$DEADC0DE,(A2)+    ; trash it, safer
  1095.     dbf    D3,.allocloop
  1096.     movem.l    (A7)+,D0-A6
  1097.     rts
  1098.  
  1099. ; ClearPointer, added by JOTD
  1100.  
  1101. _ClearPointer:
  1102.     move.l    _CursorSpriteData(pc),D0
  1103.     beq.b    .end
  1104.     move.l    D0,A0
  1105.     moveq.l    #POINTER_HEIGHT*2-1,D0
  1106. .loop
  1107.     clr.l    (a0)+
  1108.     dbf    D0,.loop
  1109. .end
  1110.     rts
  1111.  
  1112. ; SetPointer, added by JOTD
  1113.  
  1114. _SetPointer:
  1115.     bsr    create_sprite_pointer
  1116.  
  1117.     move.l    A1,(wd_Pointer,A0)
  1118.     move.w    D0,(wd_PtrHeight,A0)
  1119.     move.w    D1,(wd_PtrWidth,A0)
  1120.     move.b    D2,(wd_XOffset,A0)
  1121.     move.b    D3,(wd_YOffset,A0)
  1122.  
  1123.     movem.l    A2/A6,-(A7)
  1124.  
  1125.     move.l    A1,A2
  1126.     lea    _CursorSpriteStruct(pc),A1
  1127.     clr.l    (A1)
  1128.     clr.w    (ss_num,A1)        ; first sprite
  1129.     move.w    D0,(ss_height,A1)
  1130.  
  1131.     move.w    (wd_MouseX,A0),D0
  1132.     addx.b    D2,D0
  1133.     move.w    D0,(ss_x,A1)
  1134.     move.w    (wd_MouseY,A0),D0
  1135.     addx.b    D3,D0
  1136.     move.w    D0,(ss_y,A1)
  1137.  
  1138.     sub.l    A0,A0    ; no view port!
  1139.     move.l    _gfxbase(pc),A6
  1140.     JSRLIB    ChangeSprite
  1141.  
  1142.     movem.l    (A7)+,A2/A6
  1143.     rts
  1144.  
  1145.  
  1146. ; ModifyIDCMP (JOTD)
  1147. ; < A0: window
  1148. ; < D0: new flags
  1149.  
  1150. _ModifyIDCMP:
  1151.     MOVE.L    D0,wd_IDCMPFlags(A0)
  1152.     moveq.l    #1,D0
  1153.     rts
  1154.  
  1155. _WBenchToFront
  1156. _WBenchToBack
  1157.     moveq.l    #-1,D0
  1158.     RTS
  1159.  
  1160. ; ReportMouse (JOTD)
  1161. ; < A0: window
  1162. ; < D0: boolean
  1163.  
  1164. _ReportMouse
  1165.     or.w    #WFLG_REPORTMOUSE,(wd_Flags,A0)
  1166.     tst.l    D0
  1167.     bne.b    .exit
  1168.     and.w    #~WFLG_REPORTMOUSE,(wd_Flags,A0)
  1169. .exit
  1170.     rts
  1171. prefsdata:
  1172.     include    "prefs.s"
  1173.     even
  1174.  
  1175.